home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / Array.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  32.5 KB  |  894 lines

  1. #include-once
  2. #include <GuiConstants.au3>
  3. #include <GuiListView.au3>
  4.  
  5. ; ------------------------------------------------------------------------------
  6. ;
  7. ; AutoIt Version: 3.0
  8. ; Language:       English
  9. ; Description:    Functions that assist with array management.
  10. ;
  11. ; Apr 28, 2005 - Fixed _ArrayTrim(): $iTrimDirection test.
  12. ; ------------------------------------------------------------------------------
  13.  
  14.  
  15.  
  16.  
  17. ;===============================================================================
  18. ;
  19. ; Function Name:  _ArrayAdd()
  20. ; Description:    Adds a specified value at the end of an array, returning the
  21. ;                 adjusted array.
  22. ; Author(s):      Jos van der Zande <jdeb at autoitscript dot com>
  23. ;
  24. ;===============================================================================
  25. Func _ArrayAdd(ByRef $avArray, $sValue)
  26.     If IsArray($avArray) Then
  27.         ReDim $avArray[UBound($avArray) + 1]
  28.         $avArray[UBound($avArray) - 1] = $sValue
  29.         SetError(0)
  30.         Return 1
  31.     Else
  32.         SetError(1)
  33.         Return 0
  34.     EndIf
  35. EndFunc   ;==>_ArrayAdd
  36.  
  37.  
  38. ;===============================================================================
  39. ;
  40. ; Function Name:  _ArrayBinarySearch()
  41. ; Description:    Uses the binary search algorithm to search through a
  42. ;                 1-dimensional array.
  43. ; Author(s):      Jos van der Zande <jdeb at autoitscript dot com>
  44. ;
  45. ;===============================================================================
  46. Func _ArrayBinarySearch(ByRef $avArray, $sKey, $i_Base = 0)
  47.     Local $iLwrLimit = $i_Base
  48.     Local $iUprLimit
  49.     Local $iMidElement
  50.  
  51.     If (Not IsArray($avArray)) Then
  52.         SetError(1)
  53.         Return ""
  54.     EndIf
  55.     $iUprLimit = UBound($avArray) - 1
  56.     $iMidElement = Int(($iUprLimit + $iLwrLimit) / 2)
  57.     ; sKey is smaller than the first entry
  58.     If $avArray[$iLwrLimit] > $sKey Or $avArray[$iUprLimit] < $sKey Then
  59.         SetError(2)
  60.         Return ""
  61.     EndIf
  62.  
  63.     While $iLwrLimit <= $iMidElement And $sKey <> $avArray[$iMidElement]
  64.         If $sKey < $avArray[$iMidElement] Then
  65.             $iUprLimit = $iMidElement - 1
  66.         Else
  67.             $iLwrLimit = $iMidElement + 1
  68.         EndIf
  69.         $iMidElement = Int(($iUprLimit + $iLwrLimit) / 2)
  70.     WEnd
  71.     If $iLwrLimit > $iUprLimit Then
  72.         ; Entry not found
  73.         SetError(3)
  74.         Return ""
  75.     Else
  76.         ;Entry found , return the index
  77.         SetError(0)
  78.         Return $iMidElement
  79.     EndIf
  80. EndFunc   ;==>_ArrayBinarySearch
  81.  
  82. ;===============================================================================
  83. ;
  84. ; Function Name:    _ArrayCreate()
  85. ; Description:      Create a small array and quickly assign values.
  86. ; Parameter(s):     $v_0  - The first element of the array.
  87. ;                   $v_1  - The second element of the array (optional).
  88. ;                   ...
  89. ;                   $v_20 - The twentyfirst element of the array (optional).
  90. ; Requirement(s):   None.
  91. ; Return Value(s):  The array with values.
  92. ; Author(s):        Dale (Klaatu) Thompson, rewritten JdeB to avoid Eval() errors in Obsufcator
  93. ; Note(s):          None.
  94. ;
  95. ;===============================================================================
  96. Func _ArrayCreate($v_0, $v_1 = 0, $v_2 = 0, $v_3 = 0, $v_4 = 0, $v_5 = 0, $v_6 = 0, $v_7 = 0, $v_8 = 0, $v_9 = 0, $v_10 = 0, $v_11 = 0, $v_12 = 0, $v_13 = 0, $v_14 = 0, $v_15 = 0, $v_16 = 0, $v_17 = 0, $v_18 = 0, $v_19 = 0, $v_20 = 0)
  97.     Local $av_Array[21] = [$v_0, $v_1, $v_2, $v_3, $v_4, $v_5, $v_6, $v_7, $v_8, $v_9, $v_10, $v_11, $v_12, $v_13, $v_14, $v_15, $v_16, $v_17, $v_18, $v_19, $v_20]
  98.     ReDim $av_Array[@NumParams]
  99.     Return $av_Array
  100.     ; Create fake usage for the variables to suppress Au3Check -w 6
  101. EndFunc   ;==>_ArrayCreate
  102.  
  103.  
  104. ;===============================================================================
  105. ;
  106. ; Function Name:  _ArrayDelete()
  107. ; Description:    Deletes the specified element from the given array, returning
  108. ;                 the adjusted array.
  109. ; Author(s)       Cephas <cephas at clergy dot net>
  110. ; Modifications   Array is passed via Byref  - Jos van der zande
  111. ;===============================================================================
  112. Func _ArrayDelete(ByRef $avArray, $iElement)
  113.     Local $iCntr = 0, $iUpper = 0
  114.  
  115.     If (Not IsArray($avArray)) Then
  116.         SetError(1)
  117.         Return ""
  118.     EndIf
  119.  
  120.     ; We have to define this here so that we're sure that $avArray is an array
  121.     ; before we get it's size.
  122.     $iUpper = UBound($avArray)    ; Size of original array
  123.  
  124.     ; If the array is only 1 element in size then we can't delete the 1 element.
  125.     If $iUpper = 1 Then
  126.         SetError(2)
  127.         Return ""
  128.     EndIf
  129.  
  130.     Local $avNewArray[$iUpper - 1]
  131.     If $iElement < 0 Then
  132.         $iElement = 0
  133.     EndIf
  134.     If $iElement > ($iUpper - 1) Then
  135.         $iElement = ($iUpper - 1)
  136.     EndIf
  137.     If $iElement > 0 Then
  138.         For $iCntr = 0 To $iElement - 1
  139.             $avNewArray[$iCntr] = $avArray[$iCntr]
  140.         Next
  141.     EndIf
  142.     If $iElement < ($iUpper - 1) Then
  143.         For $iCntr = ($iElement + 1) To ($iUpper - 1)
  144.             $avNewArray[$iCntr - 1] = $avArray[$iCntr]
  145.         Next
  146.     EndIf
  147.     $avArray = $avNewArray
  148.     SetError(0)
  149.     Return 1
  150. EndFunc   ;==>_ArrayDelete
  151.  
  152.  
  153. ;===============================================================================
  154. ;
  155. ; Function Name:  _ArrayDisplay()
  156. ;
  157. ; Parameter(s):     $ar_2DArray      - Name of Array to display; 1 or 2 dimensional
  158. ;                   $sTitle          - [optional] The new title for Array Display ListView.
  159. ;                   $i_ShowOver4000  - [optional]     0 = Limit number of rows displayed to 4000 for speed
  160. ;                                    -                 1 = (default) Display all rows [may slow down over 4000]
  161. ;                   $i_Transpose     - [optional]     0 = (default) don't transpose view
  162. ;                                    -                 1 = transpose view
  163. ;                   $GUIDataSeparatorChar - [optional]     (default="|") change option of character for ListView display [see Opt("GUIDataSeparatorChar", $GUIDataSeparatorChar)]
  164. ;                   $GUIDataReplace       - [optional]     (default="~") change character to use in items of display if the item contains the separator character
  165. ; Requirement(s):   None
  166. ; Return Value(s):  On Success -  Returns 1
  167. ;                   On Failure -  0 , @error is set to 1.
  168. ; Author(s):        randallc
  169. ;
  170. ;=====================================================================
  171. Func _ArrayDisplay($ar_2DArray, $sTitle = "ListView array 1D and 2D Display", $i_ShowOver4000 = 1, $i_Transpose = 0, $GUIDataSeparatorChar = "|", $GUIDataReplace = "~")
  172.     Local $searchlistView, $hndButton_Close, $sTempHeader = 'Row', $i_Pos, $size, $ar_ExcelValueTrans[1][1], $s_NotDoneLine, $ret
  173.     Local $ar_TempSingle[1], $msg, $hndButton_Array1Box_TextSelect, $searchGUI, $ar_2dCurrent[1][1], $GUICtrlCreateListViewItem
  174.     If Not IsArray($ar_2DArray) Then Return SetError(1, 0, 0)
  175.     ; Create GUI and Buttons =========================================================================================
  176.     $searchGUI = GUICreate($sTitle, 810, 623, (@DesktopWidth - 800) / 2, (@DesktopHeight - 600) / 2, $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
  177.     $hndButton_Array1Box_TextSelect = GUICtrlCreateButton('&Text' & 'Selected', 10, 550, 70, 24)
  178.     GUICtrlSetResizing($hndButton_Array1Box_TextSelect, BitOR($GUI_DockRight, $GUI_DockBottom, $GUI_DockSize))
  179.     $hndButton_Close = GUICtrlCreateButton('&Close', 190, 550, 70, 24)
  180.     GUICtrlSetResizing($hndButton_Close, BitOR($GUI_DockRight, $GUI_DockBottom, $GUI_DockSize))
  181.     GUICtrlSetState($hndButton_Array1Box_TextSelect, ($GUI_DefButton))
  182.     ; for 1D; add index column; change to 2D array==================================================================
  183.     If UBound($ar_2DArray, 0) = 1 Then
  184.         ReDim $ar_2dCurrent[UBound($ar_2DArray) ][1]
  185.         For $i = 0 To UBound($ar_2DArray) - 1
  186.             $ar_2dCurrent[$i][0] = $ar_2DArray[$i]
  187.         Next
  188.         $ar_2DArray = $ar_2dCurrent
  189.     EndIf
  190.     ; transpose if requested==================================================================
  191.     If $i_Transpose And IsArray($ar_2DArray) And UBound($ar_2DArray, 0) = 2 Then ; transpose if requested
  192.         ReDim $ar_ExcelValueTrans[UBound($ar_2DArray, 2) ][UBound($ar_2DArray, 1) ]
  193.         For $j = 0 To UBound($ar_2DArray, 2) - 1
  194.             For $numb = 0 To UBound($ar_2DArray, 1) - 1
  195.                 If $numb > 250 Then ExitLoop  ; limit cols to about 250 as limitation  of GUICreatelistView?
  196.                 $ar_ExcelValueTrans[$j][$numb] = $ar_2DArray[$numb][$j]
  197.             Next
  198.         Next
  199.         $ar_2DArray = $ar_ExcelValueTrans
  200.     EndIf
  201.     ;Replace any array items containing the LV separator character =============================================
  202.     Opt("GUIDataSeparatorChar", $GUIDataSeparatorChar) ;"|" is the default
  203.     For $x = 0 To UBound($ar_2DArray) - 1 Step 1
  204.         For $y = 0 To UBound($ar_2DArray, 2) - 1 Step 1
  205.             $ar_2DArray[$x][$y] = StringReplace($ar_2DArray[$x][$y], $GUIDataSeparatorChar, $GUIDataReplace)
  206.         Next
  207.     Next
  208.     ;; make LV header==================================================================
  209.     For $i = 1 To UBound($ar_2DArray, 2)
  210.         $sTempHeader &= $GUIDataSeparatorChar & 'Col ' & $i - 1
  211.     Next
  212.     StringReplace($sTempHeader, $GUIDataSeparatorChar, "<")
  213.     If @extended > 252 Then
  214.         $i_Pos = StringInStr($sTempHeader, $GUIDataSeparatorChar, 0, 252)
  215.         $sTempHeader = StringLeft($sTempHeader, $i_Pos - 1)
  216.     EndIf
  217.     $s_NotDoneLine = StringReplace($sTempHeader, "Col", "ND")
  218.     ;change 2D array to Array LV formatted rows==================================================================
  219.     If UBound($ar_2DArray, 0) = 2 Then
  220.         ReDim $ar_TempSingle[UBound($ar_2DArray) ]
  221.         For $i = 0 To UBound($ar_2DArray) - 1
  222.             $ar_TempSingle[$i] = "[" & $i & "]"
  223.             For $c = 0 To UBound($ar_2DArray, 2) - 1 ;0 is base
  224.                 If $c < 251 Then
  225.                     $ar_TempSingle[$i] &= $GUIDataSeparatorChar & $ar_2DArray[$i][$c]
  226.                 Else
  227.                     ExitLoop;$c = UBound($ar_2DArray, 2) - 1
  228.                 EndIf
  229.             Next
  230.             $ar_TempSingle[$i] = StringMid($ar_TempSingle[$i], 1, StringLen($ar_TempSingle) - 1)
  231.         Next
  232.     Else
  233.         $ar_TempSingle = $ar_2DArray
  234.     EndIf
  235.     ;Create Listview==================================================================
  236.     $size = WinGetClientSize($searchGUI)
  237.     GUICtrlDelete($searchlistView)
  238.     $searchlistView = GUICtrlCreateListView($sTempHeader, 0, 16, $size[0] - 10, $size[1] - 90, BitOR($LVS_SHOWSELALWAYS, $LVS_EDITLABELS), BitOR($LVS_EX_GRIDLINES, $LVS_EX_HEADERDRAGDROP, $LVS_EX_FULLROWSELECT, $LVS_EX_REGIONAL))
  239.     GUICtrlSetResizing($searchlistView, BitOR($GUI_DockLeft, $GUI_DockTop, $GUI_DockRight, $GUI_DockBottom))
  240.     For $c = 0 To UBound($ar_TempSingle) - 1
  241.         If ($c < 3999) Or $i_ShowOver4000 Then
  242.             If $c < 3999 Then
  243.                 $GUICtrlCreateListViewItem = GUICtrlCreateListViewItem($ar_TempSingle[$c], $searchlistView)
  244.                 If Not $GUICtrlCreateListViewItem Then GUICtrlCreateListViewItem($s_NotDoneLine, $searchlistView)
  245.             Else
  246.                 $ret = _GUICtrlListViewInsertItem($searchlistView, -1, $ar_TempSingle[$c])
  247.                 If ($ret = $LV_ERR) Then _GUICtrlListViewInsertItem($searchlistView, -1, $s_NotDoneLine)
  248.             EndIf
  249.         ElseIf ($c >= 3999) Then
  250.             ExitLoop
  251.         EndIf
  252.     Next
  253.     _GUICtrlListViewSetColumnWidth($searchlistView, 2, $LVSCW_AUTOSIZE)
  254.     If UBound($ar_2DArray, 2) = 1 Then _GUICtrlListViewSetColumnWidth($searchlistView, 1, $LVSCW_AUTOSIZE)
  255.     GUISetState()
  256.     Local $SaveEventMode = Opt("GUIOnEventMode",0) 
  257.     Do ; LOOP
  258.         $msg = GUIGetMsg(1)
  259.         Select
  260.             ;Copy all to clipboard(default); or multiple selected rows===============================================================)
  261.             Case $msg[0] = $hndButton_Array1Box_TextSelect
  262.                 Local $a_indices[1], $s_CopyLines = ""
  263.                 If _GUICtrlListViewGetItemCount($searchlistView) Then $a_indices = _GUICtrlListViewGetSelectedIndices($searchlistView, 1)
  264.                 If (IsArray($a_indices)) Then
  265.                     ClipPut("")
  266.                     For $i = 1 To $a_indices[0]
  267.                         $s_CopyLines &= $ar_TempSingle[ $a_indices[$i]] & @LF
  268.                     Next
  269.                 Else
  270.                     For $i = 0 To UBound($ar_TempSingle) - 1
  271.                         $s_CopyLines &= $ar_TempSingle[$i] & @LF
  272.                     Next
  273.                 EndIf
  274.                 ClipPut($s_CopyLines)
  275.         EndSelect
  276.     Until $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $hndButton_Close
  277.     GUIDelete($searchGUI)
  278.     Opt("GUIOnEventMode",$SaveEventMode) 
  279.     Return SetError(0, 0, 1)
  280. EndFunc   ;==>_ArrayDisplay
  281.  
  282. ;===============================================================================
  283. ;
  284. ; Function Name:  _ArrayInsert()
  285. ; Description:    Add a new value at the specified position.
  286. ;
  287. ; Author(s):      Jos van der Zande <jdeb at autoitscript dot com>
  288. ;
  289. ;===============================================================================
  290. Func _ArrayInsert(ByRef $avArray, $iElement, $sValue = "")
  291.     Local $iCntr = 0
  292.  
  293.     If Not IsArray($avArray) Then
  294.         SetError(1)
  295.         Return 0
  296.     EndIf
  297.     ; Add 1 to the Array
  298.     ReDim $avArray[UBound($avArray) + 1]
  299.     ; Move all entries one up till the specified Element
  300.     For $iCntr = UBound($avArray) - 1 To $iElement + 1 Step - 1
  301.         $avArray[$iCntr] = $avArray[$iCntr - 1]
  302.     Next
  303.     ; add the value in the specified element
  304.     $avArray[$iCntr] = $sValue
  305.     Return 1
  306. EndFunc   ;==>_ArrayInsert
  307.  
  308.  
  309. ;===============================================================================
  310. ;
  311. ; Function Name:  _ArrayMax()
  312. ; Description:    Returns the highest value held in an array.
  313. ; Author(s):      Cephas <cephas at clergy dot net>
  314. ;
  315. ;                 Jos van der Zande
  316. ; Modified:       Added $iCompNumeric and $i_Base parameters and logic
  317. ;===============================================================================
  318. Func _ArrayMax(Const ByRef $avArray, $iCompNumeric = 0, $i_Base = 0)
  319.     If IsArray($avArray) Then
  320.         Return $avArray[_ArrayMaxIndex($avArray, $iCompNumeric, $i_Base) ]
  321.     Else
  322.         SetError(1)
  323.         Return ""
  324.     EndIf
  325. EndFunc   ;==>_ArrayMax
  326.  
  327.  
  328. ;===============================================================================
  329. ;
  330. ; Function Name:  _ArrayMaxIndex()
  331. ; Description:    Returns the index where the highest value occurs in the array.
  332. ; Author(s):      Cephas <cephas at clergy dot net>
  333. ;
  334. ;                 Jos van der Zande
  335. ; Modified:       Added $iCompNumeric and $i_Base parameters and logic
  336. ;===============================================================================
  337. Func _ArrayMaxIndex(Const ByRef $avArray, $iCompNumeric = 0, $i_Base = 0)
  338.     Local $iCntr, $iMaxIndex = $i_Base
  339.  
  340.     If Not IsArray($avArray) Then
  341.         SetError(1)
  342.         Return ""
  343.     EndIf
  344.  
  345.     Local $iUpper = UBound($avArray)
  346.     For $iCntr = $i_Base To ($iUpper - 1)
  347.         If $iCompNumeric = 1 Then
  348.             If Number($avArray[$iMaxIndex]) < Number($avArray[$iCntr]) Then
  349.                 $iMaxIndex = $iCntr
  350.             EndIf
  351.         Else
  352.             If $avArray[$iMaxIndex] < $avArray[$iCntr] Then
  353.                 $iMaxIndex = $iCntr
  354.             EndIf
  355.         EndIf
  356.     Next
  357.     SetError(0)
  358.     Return $iMaxIndex
  359. EndFunc   ;==>_ArrayMaxIndex
  360.  
  361.  
  362. ;===============================================================================
  363. ;
  364. ; Function Name:  _ArrayMin()
  365. ; Description:    Returns the lowest value held in an array.
  366. ; Author(s):      Cephas <cephas ay clergy dot net>
  367. ;
  368. ;                 Jos van der Zande
  369. ; Modified:       Added $iCompNumeric and $i_Base parameters and logic
  370. ;===============================================================================
  371. Func _ArrayMin(Const ByRef $avArray, $iCompNumeric = 0, $i_Base = 0)
  372.     If IsArray($avArray) Then
  373.         Return $avArray[_ArrayMinIndex($avArray, $iCompNumeric, $i_Base) ]
  374.     Else
  375.         SetError(1)
  376.         Return ""
  377.     EndIf
  378. EndFunc   ;==>_ArrayMin
  379.  
  380.  
  381. ;===============================================================================
  382. ;
  383. ; Function Name:  _ArrayMinIndex()
  384. ; Description:    Returns the index where the lowest value occurs in the array.
  385. ; Author(s):      Cephas <cephas at clergy dot net>
  386. ;
  387. ;                 Jos van der Zande
  388. ; Modified:       Added $iCompNumeric and $i_Base parameters and logic
  389. ;===============================================================================
  390. Func _ArrayMinIndex(Const ByRef $avArray, $iCompNumeric = 0, $i_Base = 0)
  391.     Local $iCntr = 0, $iMinIndex = $i_Base
  392.  
  393.     If Not IsArray($avArray) Then
  394.         SetError(1)
  395.         Return ""
  396.     EndIf
  397.  
  398.     Local $iUpper = UBound($avArray)
  399.     For $iCntr = $i_Base To ($iUpper - 1)
  400.         If $iCompNumeric = 1 Then
  401.             If Number($avArray[$iMinIndex]) > Number($avArray[$iCntr]) Then
  402.                 $iMinIndex = $iCntr
  403.             EndIf
  404.         Else
  405.             If $avArray[$iMinIndex] > $avArray[$iCntr] Then
  406.                 $iMinIndex = $iCntr
  407.             EndIf
  408.         EndIf
  409.     Next
  410.     SetError(0)
  411.     Return $iMinIndex
  412. EndFunc   ;==>_ArrayMinIndex
  413.  
  414.  
  415. ;===============================================================================
  416. ;
  417. ; Function Name:  _ArrayPop()
  418. ; Description:    Returns the last element of an array, deleting that element
  419. ;                 from the array at the same time.
  420. ; Author(s):      Cephas <cephas at clergy dot net>
  421. ; Modified:       Use Redim to remove last entry.
  422. ;===============================================================================
  423. Func _ArrayPop(ByRef $avArray)
  424.     Local $sLastVal
  425.     If (Not IsArray($avArray)) Then
  426.         SetError(1)
  427.         Return ""
  428.     EndIf
  429.     $sLastVal = $avArray[UBound($avArray) - 1]
  430.     ; remove the last value
  431.     If UBound($avArray) = 1 Then
  432.         $avArray = ""
  433.     Else
  434.         ReDim $avArray[UBound($avArray) - 1]
  435.     EndIf
  436.     ; return last value
  437.     Return $sLastVal
  438. EndFunc   ;==>_ArrayPop
  439.  
  440. ;=====================================================================================
  441. ;
  442. ; Function Name:    _ArrayPush
  443. ; Description:      Add new values without increasing array size.Either by inserting
  444. ;                   at the end the new value and deleting the first one or vice versa.
  445. ; Parameter(s):     $avArray      - Array
  446. ;                   $sValue       - The new value.It can be an array too.
  447. ;                   $i_Direction  - 0 = Leftwise slide (adding at the end) (default)
  448. ;                                   1 = Rightwise slide (adding at the start)
  449. ; Requirement(s):   None
  450. ; Return Value(s):  On Success -  Returns 1
  451. ;                   On Failure -  0 if $avArray is not an array.
  452. ;                                 -1 if $sValue array size is greater than $avArray size.
  453. ;                                 In both cases @error is set to 1.
  454. ; Author(s):        Helias Gerassimou(hgeras)
  455. ;
  456. ;======================================================================================
  457. Func _ArrayPush(ByRef $avArray, $sValue, $i_Direction = 0)
  458.     Local $i, $j
  459.  
  460.     If (Not IsArray($avArray)) Then
  461.         SetError(1)
  462.         Return 0
  463.     EndIf
  464.     ;
  465.     If (Not IsArray($sValue)) Then
  466.         If $i_Direction = 1 Then
  467.             For $i = (UBound($avArray) - 1) To 1 Step - 1
  468.                 $avArray[$i] = $avArray[$i - 1]
  469.             Next
  470.             $avArray[0] = $sValue
  471.         Else
  472.             For $i = 0 To (UBound($avArray) - 2)
  473.                 $avArray[$i] = $avArray[$i + 1]
  474.             Next
  475.             $i = (UBound($avArray) - 1)
  476.             $avArray[$i] = $sValue
  477.         EndIf
  478.         ;
  479.         SetError(0)
  480.         Return 1
  481.     Else
  482.         If UBound($sValue) > UBound($avArray) Then
  483.             SetError(1)
  484.             Return -1
  485.         Else
  486.             For $j = 0 To (UBound($sValue) - 1)
  487.                 If $i_Direction = 1 Then
  488.                     For $i = (UBound($avArray) - 1) To 1
  489.                         $avArray[$i] = $avArray[$i - 1]
  490.                     Next
  491.                     $avArray[$j] = $sValue[$j]
  492.                 Else
  493.                     For $i = 0 To (UBound($avArray) - 2)
  494.                         $avArray[$i] = $avArray[$i + 1]
  495.                     Next
  496.                     $i = (UBound($avArray) - 1)
  497.                     $avArray[$i] = $sValue[$j]
  498.                 EndIf
  499.             Next
  500.         EndIf
  501.     EndIf
  502.     ;
  503.     SetError(0)
  504.     Return 1
  505.     ;
  506. EndFunc   ;==>_ArrayPush
  507.  
  508. ;===============================================================================
  509. ;
  510. ; Function Name:  _ArrayReverse()
  511. ; Description:    Takes the given array and reverses the order in which the
  512. ;                 elements appear in the array.
  513. ; Author(s):      Brian Keene <brian_keene at yahoo dot com>
  514. ;
  515. ; Modified:       Added $i_Base parameter and logic (Jos van der Zande)
  516. ;                 Added $i_UBound parameter and rewrote it for speed. (Tylo)
  517. ;===============================================================================
  518.  
  519. Func _ArrayReverse(ByRef $avArray, $i_Base = 0, $i_UBound = 0)
  520.     If Not IsArray($avArray) Then
  521.         SetError(1)
  522.         Return 0
  523.     EndIf
  524.     Local $tmp, $last = UBound($avArray) - 1
  525.     If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
  526.     For $i = $i_Base To $i_Base + Int(($i_UBound - $i_Base - 1) / 2)
  527.         $tmp = $avArray[$i]
  528.         $avArray[$i] = $avArray[$i_UBound]
  529.         $avArray[$i_UBound] = $tmp
  530.         $i_UBound = $i_UBound - 1
  531.     Next
  532.     Return 1
  533. EndFunc   ;==>_ArrayReverse
  534.  
  535. ;===============================================================================
  536. ;
  537. ; Function Name:    _ArraySearch()
  538. ; Description:      Finds an entry within a one-dimensional array. (Similar to _ArrayBinarySearch() except the array does not need to be sorted.)
  539. ; Syntax:           _ArraySearch($avArray, $vWhat2Find, $iStart = 0, $iEnd = 0,$iCaseSense=0, $fPartialSearch = False)
  540. ;
  541. ; Parameter(s):     $avArray           = The array to search
  542. ;                   $vWhat2Find        = What to search $avArray for
  543. ;                   $iStart (Optional) = Start array index for search, normally set to 0 or 1. If omitted it is set to 0
  544. ;                   $iEnd  (Optional)  = End array index for search. If omitted or set to 0 it is set to Ubound($AvArray)-
  545. ;                    $iCaseSense (Optional) = If set to 1 then search is case sensitive
  546. ;                    $fPartialSearch (Optional) = If set to True then executes a partial search. If omitted it is set to False
  547. ; Requirement(s):   None
  548. ;
  549. ; Return Value(s):  On Success - Returns the position of an item in an array.
  550. ;                   On Failure - Returns an -1 if $vWhat2Find is not found
  551. ;                        @Error=1 $avArray is not an array
  552. ;                        @Error=2 $iStart is greater than UBound($AvArray)-1
  553. ;                        @Error=3 $iEnd is greater than UBound($AvArray)-1
  554. ;                        @Error=4 $iStart is greater than $iEnd
  555. ;                         @Error=5 $iCaseSense was invalid. (Must be 0 or 1)
  556. ;                         @Error=6 $vWhat2Find was not found in $avArray
  557. ;
  558. ; Author(s):        SolidSnake <MetalGX91 at GMail dot com> - updated by gcriaco <gcriaco at gmail dot com>
  559. ; Note(s):          This might be slower than _ArrayBinarySearch() but is useful when the array's order can't be altered.
  560. ;===============================================================================
  561. Func _ArraySearch(Const ByRef $avArray, $vWhat2Find, $iStart = 0, $iEnd = 0, $iCaseSense = 0, $fPartialSearch = False)
  562.     Local $iCurrentPos, $iUBound, $iResult
  563.     If Not IsArray($avArray) Then
  564.         SetError(1)
  565.         Return -1
  566.     EndIf
  567.     $iUBound = UBound($avArray) - 1
  568.     If $iEnd = 0 Then $iEnd = $iUBound
  569.     If $iStart > $iUBound Then
  570.         SetError(2)
  571.         Return -1
  572.     EndIf
  573.     If $iEnd > $iUBound Then
  574.         SetError(3)
  575.         Return -1
  576.     EndIf
  577.     If $iStart > $iEnd Then
  578.         SetError(4)
  579.         Return -1
  580.     EndIf
  581.     If Not ($iCaseSense = 0 Or $iCaseSense = 1) Then
  582.         SetError(5)
  583.         Return -1
  584.     EndIf
  585.     For $iCurrentPos = $iStart To $iEnd
  586.         Select
  587.             Case $iCaseSense = 0
  588.                 If $fPartialSearch = False Then
  589.                     If $avArray[$iCurrentPos] = $vWhat2Find Then
  590.                         SetError(0)
  591.                         Return $iCurrentPos
  592.                     EndIf
  593.                 Else
  594.                     $iResult = StringInStr($avArray[$iCurrentPos], $vWhat2Find, $iCaseSense)
  595.                     If $iResult > 0 Then
  596.                         SetError(0)
  597.                         Return $iCurrentPos
  598.                     EndIf
  599.                 EndIf
  600.             Case $iCaseSense = 1
  601.                 If $fPartialSearch = False Then
  602.                     If $avArray[$iCurrentPos] == $vWhat2Find Then
  603.                         SetError(0)
  604.                         Return $iCurrentPos
  605.                     EndIf
  606.                 Else
  607.                     $iResult = StringInStr($avArray[$iCurrentPos], $vWhat2Find, $iCaseSense)
  608.                     If $iResult > 0 Then
  609.                         SetError(0)
  610.                         Return $iCurrentPos
  611.                     EndIf
  612.                 EndIf
  613.         EndSelect
  614.     Next
  615.     SetError(6)
  616.     Return -1
  617. EndFunc   ;==>_ArraySearch
  618.  
  619. ;===============================================================================
  620. ;
  621. ; Function Name:    _ArraySort()
  622. ; Description:      Sort an 1 or 2 dimensional Array on a specific index
  623. ;                   using the quicksort/insertsort algorithms.
  624. ; Parameter(s):     $a_Array      - Array
  625. ;                   $i_Descending - Sort Descending when 1
  626. ;                   $i_Base       - Start sorting at this Array entry.
  627. ;                   $I_Ubound     - End sorting at this Array entry.
  628. ;                                   Default UBound($a_Array) - 1
  629. ;                   $i_Dim        - Elements to sort in second dimension
  630. ;                   $i_SortIndex  - The Index to Sort the Array on.
  631. ;                                   (for 2-dimensional arrays only)
  632. ; Requirement(s):   None
  633. ; Return Value(s):  On Success - 1 and the sorted array is set
  634. ;                   On Failure - 0 and sets @ERROR = 1
  635. ; Author(s):        Jos van der Zande <jdeb at autoitscript dot com>
  636. ;                   LazyCoder - added $i_SortIndex option
  637. ;                   Tylo - implemented stable QuickSort algo
  638. ;                   Jos - Changed logic to correctly Sort arrays with mixed Values and Strings
  639. ;
  640. ;===============================================================================
  641. ;
  642. Func _ArraySort(ByRef $a_Array, $i_Decending = 0, $i_Base = 0, $i_UBound = 0, $i_Dim = 1, $i_SortIndex = 0)
  643.     ; Set to ubound when not specified
  644.     If Not IsArray($a_Array) Then
  645.         SetError(1)
  646.         Return 0
  647.     EndIf
  648.     Local $last = UBound($a_Array) - 1
  649.     If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
  650.  
  651.     If $i_Dim = 1 Then
  652.         __ArrayQSort1($a_Array, $i_Base, $i_UBound)
  653.         If $i_Decending Then _ArrayReverse($a_Array, $i_Base, $i_UBound)
  654.     Else
  655.         __ArrayQSort2($a_Array, $i_Base, $i_UBound, $i_Dim, $i_SortIndex, $i_Decending)
  656.     EndIf
  657.     Return 1
  658. EndFunc   ;==>_ArraySort
  659.  
  660. ; Private
  661. Func __ArrayQSort1(ByRef $array, ByRef $left, ByRef $right)
  662.     Local $i, $j, $t
  663.     If $right - $left < 10 Then
  664.         ; InsertSort - fastest on small segments (= 25% total speedup)
  665.         For $i = $left + 1 To $right
  666.             $t = $array[$i]
  667.             $j = $i
  668.             While $j > $left _
  669.                     And ((IsNumber($array[$j - 1]) = IsNumber($t) And $array[$j - 1] > $t) _
  670.                     Or (IsNumber($array[$j - 1]) <> IsNumber($t) And String($array[$j - 1]) > String($t)))
  671.                 $array[$j] = $array[$j - 1]
  672.                 $j = $j - 1
  673.             WEnd
  674.             $array[$j] = $t
  675.         Next
  676.         Return
  677.     EndIf
  678.  
  679.     ; QuickSort - fastest on large segments
  680.     Local $pivot = $array[Int(($left + $right) / 2) ]
  681.     Local $L = $left
  682.     Local $R = $right
  683.     Do
  684.         While ((IsNumber($array[$L]) = IsNumber($pivot) And $array[$L] < $pivot) _
  685.                 Or (IsNumber($array[$L]) <> IsNumber($pivot) And String($array[$L]) < String($pivot)))
  686.             ;While $array[$L] < $pivot
  687.             $L = $L + 1
  688.         WEnd
  689.         While ((IsNumber($array[$R]) = IsNumber($pivot) And $array[$R] > $pivot) _
  690.                 Or (IsNumber($array[$R]) <> IsNumber($pivot) And String($array[$R]) > String($pivot)))
  691.             ;    While $array[$R] > $pivot
  692.             $R = $R - 1
  693.         WEnd
  694.         ; Swap
  695.         If $L <= $R Then
  696.             $t = $array[$L]
  697.             $array[$L] = $array[$R]
  698.             $array[$R] = $t
  699.             $L = $L + 1
  700.             $R = $R - 1
  701.         EndIf
  702.     Until $L > $R
  703.  
  704.     __ArrayQSort1($array, $left, $R)
  705.     __ArrayQSort1($array, $L, $right)
  706. EndFunc   ;==>__ArrayQSort1
  707.  
  708. ; Private
  709. Func __ArrayQSort2(ByRef $array, ByRef $left, ByRef $right, ByRef $dim2, ByRef $sortIdx, ByRef $decend)
  710.     If $left >= $right Then Return
  711.     Local $t, $d2 = $dim2 - 1
  712.     Local $pivot = $array[Int(($left + $right) / 2) ][$sortIdx]
  713.     Local $L = $left
  714.     Local $R = $right
  715.     Do
  716.         If $decend Then
  717.             While ((IsNumber($array[$L][$sortIdx]) = IsNumber($pivot) And $array[$L][$sortIdx] > $pivot) _
  718.                     Or (IsNumber($array[$L][$sortIdx]) <> IsNumber($pivot) And String($array[$L][$sortIdx]) > String($pivot)))
  719.                 ;While $array[$L][$sortIdx] > $pivot
  720.                 $L = $L + 1
  721.             WEnd
  722.             While ((IsNumber($array[$R][$sortIdx]) = IsNumber($pivot) And $array[$R][$sortIdx] < $pivot) _
  723.                     Or (IsNumber($array[$R][$sortIdx]) <> IsNumber($pivot) And String($array[$R][$sortIdx]) < String($pivot)))
  724.                 ;While $array[$R][$sortIdx] < $pivot
  725.                 $R = $R - 1
  726.             WEnd
  727.         Else
  728.             While ((IsNumber($array[$L][$sortIdx]) = IsNumber($pivot) And $array[$L][$sortIdx] < $pivot) _
  729.                     Or (IsNumber($array[$L][$sortIdx]) <> IsNumber($pivot) And String($array[$L][$sortIdx]) < String($pivot)))
  730.                 ;While $array[$L][$sortIdx] < $pivot
  731.                 $L = $L + 1
  732.             WEnd
  733.             While ((IsNumber($array[$R][$sortIdx]) = IsNumber($pivot) And $array[$R][$sortIdx] > $pivot) _
  734.                     Or (IsNumber($array[$R][$sortIdx]) <> IsNumber($pivot) And String($array[$R][$sortIdx]) > String($pivot)))
  735.                 ;While $array[$R][$sortIdx] > $pivot
  736.                 $R = $R - 1
  737.             WEnd
  738.         EndIf
  739.         If $L <= $R Then
  740.             For $x = 0 To $d2
  741.                 $t = $array[$L][$x]
  742.                 $array[$L][$x] = $array[$R][$x]
  743.                 $array[$R][$x] = $t
  744.             Next
  745.             $L = $L + 1
  746.             $R = $R - 1
  747.         EndIf
  748.     Until $L > $R
  749.  
  750.     __ArrayQSort2($array, $left, $R, $dim2, $sortIdx, $decend)
  751.     __ArrayQSort2($array, $L, $right, $dim2, $sortIdx, $decend)
  752. EndFunc   ;==>__ArrayQSort2
  753.  
  754.  
  755.  
  756. ;===============================================================================
  757. ;
  758. ; Function Name:  _ArraySwap()
  759. ; Description:    Swaps two elements of an array.
  760. ; Author(s):      David Nuttall <danuttall at rocketmail dot com>
  761. ;
  762. ;===============================================================================
  763. Func _ArraySwap(ByRef $svector1, ByRef $svector2)
  764.     Local $sTemp = $svector1
  765.  
  766.     $svector1 = $svector2
  767.     $svector2 = $sTemp
  768.  
  769.     SetError(0)
  770. EndFunc   ;==>_ArraySwap
  771.  
  772.  
  773. ;===============================================================================
  774. ;
  775. ; Function Name:  _ArrayToClip()
  776. ; Description:    Sends the contents of an array to the clipboard.
  777. ; Author(s):      Cephas <cephas at clergy dot net>
  778. ;
  779. ;                 Jos van der Zande
  780. ; Modified:       Added $i_Base parameter and logic
  781. ;===============================================================================
  782. Func _ArrayToClip(Const ByRef $avArray, $i_Base = 0)
  783.     Local $iCntr, $iRetVal = 0, $sCr = "", $sText = ""
  784.  
  785.     If (IsArray($avArray)) Then
  786.         For $iCntr = $i_Base To (UBound($avArray) - 1)
  787.             $iRetVal = 1
  788.             If $iCntr > $i_Base Then
  789.                 $sCr = @CR
  790.             EndIf
  791.             $sText = $sText & $sCr & $avArray[$iCntr]
  792.         Next
  793.     EndIf
  794.     ClipPut($sText)
  795.     Return $iRetVal
  796. EndFunc   ;==>_ArrayToClip
  797.  
  798.  
  799. ;===============================================================================
  800. ;
  801. ; Function Name:  _ArrayToString()
  802. ; Description:    Places the elements of an array into a single string,
  803. ;                 separated by the specified delimiter.
  804. ; Author(s):      Brian Keene <brian_keene at yahoo dot com>
  805. ;                        Rewritten by: Valik
  806. ;
  807. ;===============================================================================
  808. Func _ArrayToString(Const ByRef $avArray, $sDelim, $iStart = Default, $iEnd = Default)
  809.     ; Declare local variables.
  810.     Local $iUBound = UBound($avArray) - 1
  811.  
  812.     ; Validate the array
  813.     If ($iUBound + 1) < 1 Or UBound($avArray, 0) > 1 Then Return SetError(1, 0, "")
  814.  
  815.     ; Expand Default parameters
  816.     If $iStart = Default Or $iStart = -1 Then $iStart = 0
  817.     If $iEnd = Default Or $iEnd = -1 Then $iEnd = $iUBound
  818.  
  819.     ; Validate that the start and end indices are valid.
  820.     If ($iStart < 0) Or ($iEnd < 0) Or ($iStart > $iEnd) Then Return SetError(2, 0, "")
  821.  
  822.     ; Make sure that $iEnd <= to the size of the array.
  823.     If ($iEnd > $iUBound) Then
  824.         $iEnd = $iUBound
  825.     EndIf
  826.  
  827.     Local $sResult
  828.     ; Combine the elements into the string.
  829.     For $i = $iStart To $iEnd
  830.         $sResult &= $avArray[$i] & $sDelim
  831.     Next
  832.  
  833.     Return StringTrimRight($sResult, StringLen($sDelim))
  834. EndFunc   ;==>_ArrayToString
  835.  
  836. ;===============================================================================
  837. ;
  838. ; FunctionName:     _ArrayTrim()
  839. ; Description:      Trims all elements in an array a certain number of characters.
  840. ; Syntax:           _ArrayTrim( $aArray, $iTrimNum , [$iTrimDirection] , [$iBase] , [$iUbound] )
  841. ; Parameter(s):     $aArray              - The array to trim the items of
  842. ;                   $iTrimNum            - The amount of characters to trim
  843. ;                    $iTrimDirection     - 0 to trim left, 1 to trim right
  844. ;                                            [Optional] : Default = 0
  845. ;                   $iBase               - Start trimming at this element in the array
  846. ;                                            [Optional] : Default = 0
  847. ;                   $iUbound             - End trimming at this element in the array
  848. ;                                            [Optional] : Default = Full Array
  849. ; Requirement(s):   None
  850. ; Return Value(s):  1 - If invalid array
  851. ;                   2 - Invalid base boundry parameter
  852. ;                   3 - Invalid end boundry parameter
  853. ;                   4 - If $iTrimDirection is not a zero or a one
  854. ;                    Otherwise it returns the new trimmed array
  855. ; Author(s):        Adam Moore (redndahead)
  856. ; Note(s):          None
  857. ;
  858. ;===============================================================================
  859. Func _ArrayTrim($aArray, $iTrimNum, $iTrimDirection = 0, $iBase = 0, $iUBound = 0)
  860.     Local $i
  861.  
  862.     ;Validate array and options given
  863.     If UBound($aArray) = 0 Then
  864.         SetError(1)
  865.         Return $aArray
  866.     EndIf
  867.  
  868.     If $iBase < 0 Or Not IsNumber($iBase) Then
  869.         SetError(2)
  870.         Return $aArray
  871.     EndIf
  872.  
  873.     If UBound($aArray) <= $iUBound Or Not IsNumber($iUBound) Then
  874.         SetError(3)
  875.         Return $aArray
  876.     EndIf
  877.  
  878.     ; Set to ubound when not specified
  879.     If $iUBound < 1 Then $iUBound = UBound($aArray) - 1
  880.  
  881.     If $iTrimDirection < 0 Or $iTrimDirection > 1 Then
  882.         SetError(4)
  883.         Return
  884.     EndIf
  885.     ;Trim it off
  886.     For $i = $iBase To $iUBound
  887.         If $iTrimDirection = 0 Then
  888.             $aArray[$i] = StringTrimLeft($aArray[$i], $iTrimNum)
  889.         Else
  890.             $aArray[$i] = StringTrimRight($aArray[$i], $iTrimNum)
  891.         EndIf
  892.     Next
  893.     Return $aArray
  894. EndFunc   ;==>_ArrayTrim